
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
util.PrecacheSound( "Harvest/shockwave.wav" )

function ENT:Initialize()

	self.Entity:SetName("Shockwave Warhead")
	self.Entity:SetModel( "models/items/combine_rifle_ammo01.mdl" )

	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableGravity(false)
		phys:EnableDrag(false)
		phys:EnableCollisions(false)
	end

	self.PhysObj = self.Entity:GetPhysicsObject()
	self.STime = CurTime()
	self.BTime = self.STime + 3

	self.Entity:SetNetworkedFloat( "FireTime", CurTime() )
	
end

function ENT:PhysicsUpdate()

end


function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end

	local SpawnPos = tr.HitPos + tr.HitNormal * 36

	local ent = ents.Create( "plasbomb_head" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:Think()
	self.Entity:SetColor(0,0,0,1)
	
	if (CurTime() >= self.BTime && self.Blasted != true) then
		self.Blasted = true
		--self.Entity:EmitSound( "Harvest/shockwave.wav", 500, 100 )
		local x = 0

		for x = 0, 359, 10 do
			local Wave = ents.Create( "plasbomb_wave" )
			if ( !Wave:IsValid() ) then return end
			Wave:SetPos( self.Entity:GetPos() )
			Wave:SetAngles( Angle(0, x, 0) )
			Wave:Spawn()
			Wave:SetOwner( self.Entity:GetOwner() )
			Wave:Fire( "kill", "", 3)
			Wave.PhysObj:SetVelocity( Wave.Entity:GetForward() * 1000 )
		end
		for x = 0, 359, 10 do
			local Wave = ents.Create( "plasbomb_wave" )
			if ( !Wave:IsValid() ) then return end
			Wave:SetPos( self.Entity:GetPos() )
			Wave:SetAngles( Angle(x, 0, 0) )
			Wave:Spawn()
			Wave:SetOwner( self.Entity:GetOwner() )
			Wave:Fire( "kill", "", 3)
			Wave.PhysObj:SetVelocity( Wave.Entity:GetForward() * 1000 )
		end
		for x = 0, 359, 10 do
			local Wave = ents.Create( "plasbomb_wave" )
			if ( !Wave:IsValid() ) then return end
			Wave:SetPos( self.Entity:GetPos() )
			Wave:SetAngles( Angle(x, 90, 0) )
			Wave:Spawn()
			Wave:SetOwner( self.Entity:GetOwner() )
			Wave:Fire( "kill", "", 3)
			Wave.PhysObj:SetVelocity( Wave.Entity:GetForward() * 1000 )
		end
		self.Entity:Remove()
	end


end

function ENT:PhysicsCollide( data, physobj )
	
end

function ENT:OnTakeDamage( dmginfo )
	
end

function ENT:Use( activator, caller )

end